package gameElement;

import java.awt.Cursor;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.Icon;

import basicComp.BasicMoveLabel;
import basicComp.ImageGet;

/**
 * 飞机控制类
 * @author NHQ
 *
 */
public class Plane extends BasicMoveLabel
{
	private int master,index;
	
	private int nextLen;
	
	private int len = -1;
//	private int special;
//	private int skip;
	
	private boolean canMove;
	
	public Plane(Icon icon)
	{
		super(icon);
	}
	public void iniConstruc(Icon icon,int master,int index)
	{
		this.setIcon(icon);
		this.master = master;
		this.index = index;
		this.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				super.mouseClicked(e);
				if(canMove)
				{
					Manager.getManager().hasClickPlane(Plane.this);
				}
			}
		});
	}
	public int getMaster() {
		return master;
	}
	public int getIndex() {
		return index;
	}
	public void setMaster(int master) {
		this.master = master;
	}
	public void setIndex(int index) {
		this.index = index;
	}
	public int getLen() {
		return len;
	}
	public void setLen(int len) {
		this.len = len;
	}
	public void addLen(int len)
	{
//		if(this.getLen() == ChessPane.OVER_LEN)
//		{
//			this.over();
//		}
		this.len += len;
	}
	public void over()
	{
//		setIcon(icon);
	}
	
//	public boolean isOver()
//	{
//		return isOver;
//	}
	
	
	
	public boolean isCanMove() {
		return canMove;
	}
	public void setCanMove(boolean canMove) {
		this.canMove = canMove;
		if(canMove)
		{
			this.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
		}else
		{
			this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
		}
	}
	public void reset(Plane thePlane) {
		len = -1;
		new Thread(){
			public void run()
			{
				while(true){
					if(thePlane.moveIsOver())
					{
						Plane.this.setNextPosition(ChessPane.getChessPane().getHomePoint(Plane.this.getMaster(), Plane.this.getIndex()));
						return;
					}
				}
			}
		}.start();
		System.out.println(" reset(Plane thePlane)"+ master);
	}
	
	public void isOver()
	{//CHANGE
		new Thread(){
			public void run()
			{
				while(true)
				{
					if(moveIsOver())
					{
						setIcon(ImageGet.getImageGet().getOverIcon());
					}
				}
			}
		}.start();
	}
	
}
